
import java.util.Calendar;

/**
 * A shift is a class which represents a time period between
 * a start of a shift and an end of a shift.
 * @version 1.0
 */
public abstract class Shift implements Comparable<Shift>
{
    //The start time of the shift
    private Calendar startTime;
    //The end time of the shift
    private Calendar endTime;
    
    public Shift(Calendar startTime, Calendar endTime)
    {
        this.startTime = startTime;
        this.endTime = endTime;
    }

    public Calendar getEndTime() {
        return this.endTime;
    }

    public Calendar getStartTime() {
        return this.startTime;
    }

    public void setEndTime(Calendar time)
    {
        endTime = time;
    }

    public void setStartTime(Calendar time)
    {
        startTime = time;
    }
    
    public boolean isShiftIn(Shift other)
    {
        //System.out.println("Start: this - " + Service.calendarToString(this.startTime) + ", other - " + Service.calendarToString(other.startTime));

        //System.out.println("End: this - " + Service.calendarToString(this.endTime) + ", other - " + Service.calendarToString(other.endTime));
        
        return ((other.startTime.after(this.startTime) || (other.startTime.equals(this.startTime)))
                    && (other.startTime.before(this.endTime) || other.startTime.equals(this.endTime)))
                    || ((other.endTime.after(this.startTime) || other.endTime.equals(this.startTime))
                            && (other.endTime.before(this.endTime) || other.endTime.equals((this.endTime))));
    }

   /* @Override
    public int compareTo(Shift other)            
    {
        if (other.startTime.before(this.startTime) && other.endTime.before(this.endTime))
            return -1;
        else if (other.startTime.equals(this.startTime) && other.endTime.equals(this.endTime))
            return 0;
        else
            return 1;
    }*/

    @Override
    public int compareTo(Shift other)
    {
        if (other.startTime.before(this.startTime))
            return 1;
        else if (other.startTime.equals(this.startTime))
            return 0;
        else
            return -1;
    }
    
    @Override
    public boolean equals(Object other)
    {
        if (other instanceof Shift)
            return (compareTo((Shift)other) == 0);
        else
            return super.equals(other);
    }

    @Override
    public String toString() {
        return "Shift{" + "startTime=" + startTime.get(Calendar.HOUR) + ":" + startTime.get(Calendar.MINUTE) 
                + ", endTime=" + endTime.get(Calendar.HOUR) + ":" + endTime.get(Calendar.MINUTE) + '}';
    }
        
}
